﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
using System;
namespace WPFExcelReport
{

    public partial class VZABED
    {
        public void SetUpNewRow(ref DataRow dwReturn, DataRow dwInput)
        {

            switch (app.company)
            {
                case "YGR":
                case "YCC":
                case "TST":
                default:
                    #region=========
                    dwReturn["ZABMANDANT"] = app.Mandant;
                    dwReturn["ZABNR"] = "373";
                    dwReturn["ZABSPRACHKZ"] = "V ";
                    dwReturn["ZABSTATUS"] = "A";
                    dwReturn["ZABKONTOA"] = " ";
                    dwReturn["ZABBEZ"] = "                                        ";
                    dwReturn["ZABFIBU"] = "    ";
                    dwReturn["ZABZART"] = "Z";
                    dwReturn["ZABEMPF"] = " ";
                    dwReturn["ZABSKOTT1"] = "0";
                    dwReturn["ZABSKONP1"] = "0";
                    dwReturn["ZABSKOTT2"] = "1";
                    dwReturn["ZABSKONP2"] = "0";
                    dwReturn["ZABNTAGE"] = "30";
                    dwReturn["ZABNMON"] = "0";
                    dwReturn["ZABVORZZ"] = "0";
                    dwReturn["ZABVERZZ"] = "0";
                    dwReturn["ZABSSKON"] = " ";
                    dwReturn["ZABFRACH"] = " ";
                    dwReturn["ZABVERPA"] = " ";
                    dwReturn["ZABVERS"] = " ";
                    dwReturn["ZABBDAT"] = " ";
                    dwReturn["ZABBIS1"] = "00";
                    dwReturn["ZABAM1"] = "00";
                    dwReturn["ZABMON1"] = "00";
                    dwReturn["ZABBIS2"] = "00";
                    dwReturn["ZABAM2"] = "00";
                    dwReturn["ZABMON2"] = "00";
                    dwReturn["ZABBIS3"] = "00";
                    dwReturn["ZABAM3"] = "00";
                    dwReturn["ZABMON3"] = "00";
                    dwReturn["ZABZBIN1"] = "0";
                    dwReturn["ZABZBED1"] = "   ";
                    dwReturn["ZABZBIN2"] = "0";
                    dwReturn["ZABZBED2"] = "   ";
                    dwReturn["ZABZBIN3"] = "0";
                    dwReturn["ZABZBED3"] = "   ";
                    dwReturn["ZABZBIN4"] = "0";
                    dwReturn["ZABZBED4"] = "   ";
                    dwReturn["ZABZBIN5"] = "0";
                    dwReturn["ZABZBED5"] = "   ";
                    dwReturn["ZABZBIN6"] = "0";
                    dwReturn["ZABZBED6"] = "   ";
                    dwReturn["ZABANZAHLG"] = "0";
                    dwReturn["ZABGARANTYP"] = "  ";
                    dwReturn["ZABDISCCRED"] = "  ";
                    dwReturn["ZABFILLER"] = "                          ";
                    dwReturn["ZABAENZL"] = "3";
                    dwReturn["ZABAENB"] = "        ";
                    dwReturn["ZABAEND"] = "0";
                    dwReturn["ZABNEUB"] = "        ";
                    dwReturn["ZABNEUD"] = "0";

                    #endregion
                    break;
            }
            INTEXDBC.MapData(true, ref dwReturn, dwInput);
        }
        public void InsertZABED(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            dwData["ZABNEUB"] = app.User;
            dwData["ZABNEUD"] = date;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                default:
                case "YGR":
                    or1.CommandText = "INSERT INTO ZABED ( ZABMANDANT,ZABNR,ZABSPRACHKZ,ZABSTATUS,ZABKONTOA,ZABBEZ,ZABFIBU,ZABZART,ZABEMPF,ZABSKOTT1,ZABSKONP1,ZABSKOTT2,ZABSKONP2,ZABNTAGE,ZABNMON,ZABVORZZ,ZABVERZZ,ZABSSKON,ZABFRACH,ZABVERPA,ZABVERS,ZABBDAT,ZABBIS1,ZABAM1,ZABMON1,ZABBIS2,ZABAM2,ZABMON2,ZABBIS3,ZABAM3,ZABMON3,ZABZBIN1,ZABZBED1,ZABZBIN2,ZABZBED2,ZABZBIN3,ZABZBED3,ZABZBIN4,ZABZBED4,ZABZBIN5,ZABZBED5,ZABZBIN6,ZABZBED6,ZABANZAHLG,ZABGARANTYP,ZABDISCCRED,ZABFILLER,ZABAENZL,ZABAENB,ZABAEND,ZABNEUB,ZABNEUD)"
                   + " VALUES (:ZABMANDANT:,:ZABNR:,:ZABSPRACHKZ:,:ZABSTATUS:,:ZABKONTOA:,:ZABBEZ:,:ZABFIBU:,:ZABZART:,:ZABEMPF:,:ZABSKOTT1:,:ZABSKONP1:,:ZABSKOTT2:,:ZABSKONP2:,:ZABNTAGE:,:ZABNMON:,:ZABVORZZ:,:ZABVERZZ:,:ZABSSKON:,:ZABFRACH:,:ZABVERPA:,:ZABVERS:,:ZABBDAT:,:ZABBIS1:,:ZABAM1:,:ZABMON1:,:ZABBIS2:,:ZABAM2:,:ZABMON2:,:ZABBIS3:,:ZABAM3:,:ZABMON3:,:ZABZBIN1:,:ZABZBED1:,:ZABZBIN2:,:ZABZBED2:,:ZABZBIN3:,:ZABZBED3:,:ZABZBIN4:,:ZABZBED4:,:ZABZBIN5:,:ZABZBED5:,:ZABZBIN6:,:ZABZBED6:,:ZABANZAHLG:,:ZABGARANTYP:,:ZABDISCCRED:,:ZABFILLER:,:ZABAENZL:,:ZABAENB:,:ZABAEND:,:ZABNEUB:,:ZABNEUD:)";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
            }

            Connect2Proxy(or1);
        }
        public DataSet QueryZABED(DataRow dwData, int option = 1)
        {  
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ZABED WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM ZABED WHERE ZABMANDANT=:ZABMANDANT: AND ZABNR=:ZABNR: AND ZABSPRACHKZ=:ZABSPRACHKZ:"
                        + " ORDER BY ZABNR ";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM ZABED WHERE ZABMANDANT=:ZABMANDANT: AND ZABSPRACHKZ=:ZABSPRACHKZ: AND ZABBEZ LIKE '%" + dwData["ZABBEZ"].ToString().Trim() + "%'"
                        + dwData["ZABNR"].ToString()
                        + " ORDER BY ZABNR ";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case -1:
                    or1.CommandText = "SELECT ZABNR,ZABBEZ, ZABNR AS KEY,ZABBEZ AS DES,ZABSKONP1 FROM ZABED WHERE ZABMANDANT=:ZABMANDANT: AND ZABSPRACHKZ=:ZABSPRACHKZ:"
                        + " ORDER BY ZABNR ";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break; 
                default:
                    break;
            }
            SResult = Connect2Proxy(or1); 
            SResult.Tables[0].TableName = "ZABED"; 
            return SResult;
        }
        public void DeleteZABED(DataRow dwData, int option = 1)
        {
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ZABED   WHERE  ZABMANDANT=:ZABMANDANT: AND ZABNR=:ZABNR:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }

        public void UpdateZABED(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            if (dwData != null)
            {
                dwData["ZABAENB"] = app.User;
                dwData["ZABAEND"] = date;
            }
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                default:
                case 1:
                    or1.CommandText = "UPDATE ZABED SET ZABMANDANT=:ZABMANDANT:,ZABNR=:ZABNR:,ZABSPRACHKZ=:ZABSPRACHKZ:,ZABSTATUS=:ZABSTATUS:,ZABKONTOA=:ZABKONTOA:,ZABBEZ=:ZABBEZ:,ZABFIBU=:ZABFIBU:,ZABZART=:ZABZART:,ZABEMPF=:ZABEMPF:,ZABSKOTT1=:ZABSKOTT1:,ZABSKONP1=:ZABSKONP1:,ZABSKOTT2=:ZABSKOTT2:,ZABSKONP2=:ZABSKONP2:,ZABNTAGE=:ZABNTAGE:,ZABNMON=:ZABNMON:,ZABVORZZ=:ZABVORZZ:,ZABVERZZ=:ZABVERZZ:,ZABSSKON=:ZABSSKON:,ZABFRACH=:ZABFRACH:,ZABVERPA=:ZABVERPA:,ZABVERS=:ZABVERS:,ZABBDAT=:ZABBDAT:,ZABBIS1=:ZABBIS1:,ZABAM1=:ZABAM1:,ZABMON1=:ZABMON1:,ZABBIS2=:ZABBIS2:,ZABAM2=:ZABAM2:,ZABMON2=:ZABMON2:,ZABBIS3=:ZABBIS3:,ZABAM3=:ZABAM3:,ZABMON3=:ZABMON3:,ZABZBIN1=:ZABZBIN1:,ZABZBED1=:ZABZBED1:,ZABZBIN2=:ZABZBIN2:,ZABZBED2=:ZABZBED2:,ZABZBIN3=:ZABZBIN3:,ZABZBED3=:ZABZBED3:,ZABZBIN4=:ZABZBIN4:,ZABZBED4=:ZABZBED4:,ZABZBIN5=:ZABZBIN5:,ZABZBED5=:ZABZBED5:,ZABZBIN6=:ZABZBIN6:,ZABZBED6=:ZABZBED6:,ZABANZAHLG=:ZABANZAHLG:,ZABGARANTYP=:ZABGARANTYP:,ZABDISCCRED=:ZABDISCCRED:,ZABFILLER=:ZABFILLER:,ZABAENZL=:ZABAENZL:,ZABAENB=:ZABAENB:,ZABAEND=:ZABAEND:,ZABNEUB=:ZABNEUB:,ZABNEUD=:ZABNEUD:"
                        + " WHERE ZABMANDANT=:ZABMANDANT: AND ZABNR=:ZABNR: AND ZABSPRACHKZ=:ZABSPRACHKZ:"; ;
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    Connect2Proxy(or1);
                    UpdateZABED(dwData, ITXDBVERSION, 2);
                    break;
                case 2:
                    or1.CommandText = "UPDATE ZABED SET ZABZBIN1=:ZABZBIN1:,ZABZBIN2=:ZABZBIN2:,ZABZBIN3=:ZABZBIN3: "
                        + " WHERE ZABMANDANT=:ZABMANDANT: AND ZABNR=:ZABNR: "; ;
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    Connect2Proxy(or1);
                    break;
            }

        }
        public void UZA03(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();

            or1.CommandText = "UPDATE ZABED SET ZABNR=:ZABBEZ:"
                + " WHERE ZABMANDANT=:ZABMANDANT: AND ZABNR=:ZABNR: "; ;
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);

        }
    }
}
